<template>
  <div class="notice_mod" :class="themeClass">
    <v-nav :title="$t('Notice.Announcement list')"></v-nav>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh" :pulling-text="$t('info.info3')" :loosing-text="$t('info.info4')" :loading-text="$t('info.info2')" :success-text="$t('info.info5')">
      <van-list v-model="loading" :finished="finished" :loading-text="$t('info.info2')" :finished-text="$t('info.info6')" @load="onLoad">
        <van-collapse v-model="activeName">
          <van-collapse-item v-for="(item, index) in noticeList" :key="index" :title="item.notice_title" :label="item.create_time" :name="item.id">{{ item.notice_content }}</van-collapse-item>
        </van-collapse>
      </van-list>
    </van-pull-refresh>
  </div>
</template>
<script>
export default {
  name: 'Notice',
  data() {
    return {
      page: 1,
      loading: false,
      finished: false,
      refreshing: false,
      noticeList: [],
      activeName: [],
      isDayTime: false
    }
  },
  computed: {
    themeClass() {
      return this.isDayTime ? '' : 'darknight'
    },
    bgColor() {
      return this.isDayTime ? 'black' : 'white'
    },
    themeClass1() {
      return this.isDayTime ? '' : 'dark_li_color'
    }
  },
  watch: {
    '$store.state.nightMode': {
      handler(newVal) {
        this.isDayTime = newVal
      },
      immediate: true
    }
  },
  methods: {
    async getNotice() {
      await this.$https.get('/platform/getNoticeList?page=' + this.page).then(res => {
        if (this.refreshing) {
          this.noticeList = []
          this.refreshing = false
        }
        this.noticeList = [...this.noticeList, ...res.data.data]
        this.loading = false

        if (this.page >= res.data.last_page) {
          this.finished = true
        } else {
          this.page++
        }
      })
    },
    // 上拉加载处理函数
    onLoad() {
      this.getNotice()
    },
    // 下拉刷新处理函数
    onRefresh() {
      this.refreshing = true
      this.finished = false
      this.page = 1
      this.loading = true
      this.onLoad()
    }
  }
}
</script>
<style lang="less" scoped>
.notice_mod {
  min-height: 100vh;

  &_box {
    margin: 12px;

    background-color: white;
    border-radius: 4px;
    & > div {
      padding: 12px;
      margin-bottom: 10px;
      background-color: #f3f3f3;
    }
    p {
      font-family: Roboto-Regular, Roboto;
      color: #1a1a1a;
      font-size: 15px;
      line-height: 19px;
      font-weight: 400;
      margin-bottom: 4px;
    }
    span {
      font-family: Roboto-Regular, Roboto;
      font-weight: 400;
      color: #abacb7;
      font-size: 12px;
    }
  }
}
.daytime {
  background: #fff;
  color: black;
}
.active1 {
  background: #121212;
  color: #fff;
}
.darknight {
  background: #191b27 !important;
  color: #fff;
}
.dark_li_color {
  background-color: #121212 !important;
  color: #fff !important;
}
.white {
  color: #fff !important;
}
</style>
